//Jonathan Flessner
//27-April-2014
//fullDeckCount function

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"

int main(){
	int seed = time(NULL) % 5000;
	srand(seed);
	struct gameState *gS = malloc(sizeof(struct gameState));
	int numPlayers = 4;
	int testNum = 1000;
	int i = 0;
	int a = 0;
	int card = 0;
	int p = 0;
	int dCount = 0;
	int dkCount = 0;
	int hCount = 0;
	int totalCount = 0;									//expected value
	int fDC = 0;										//full deck count from function to test
	for(i = 0; i <= testNum; i++){
		p  = rand() % numPlayers;						//random player to test
		card = rand() % 27;								//random card
		gS->handCount[p] = rand() % MAX_HAND + 1;		//random num in hand
		hCount = gS->handCount[p];
		gS->deckCount[p] = rand() % MAX_DECK + 1;		//random num in deck
		dkCount = gS->deckCount[p];
		gS->discardCount[p] = rand() % MAX_DECK + 1;	//random num in discard
		dCount = gS->discardCount[p];
		totalCount = hCount + dCount + dkCount;
		for(a = 0; a < hCount; a++){
			gS->hand[p][a] = card;
		}
		for(a = 0; a < dCount; a++){
			gS->discard[p][a] = card;
		}
		for(a = 0; a < dkCount; a++){
			gS->deck[p][a] = card;
		}
		fDC = fullDeckCount(p, card, gS);

		if(totalCount == fDC){
			//printf("Pass. Count as expected.\n");
		}
		else{
			printf("FAIL. Unexpected count.\n");
			printf("Expected: %d\n", totalCount);
			printf("Return: %d\n", fDC);
			printf("Player = %d\n", p);
			printf("Hand count = %d\n", hCount);
			printf("Discard count = %d\n", dCount);
			printf("Discard count = %d\n", dkCount);
			printf("Card = %d\n", card);
			printf("Seed = %d\n", seed);
			//exit(EXIT_FAILURE);
		}
	}
	free(gS);
	printf("Seed = %d\n", seed);
	printf("Tests completed: %d. Failed tests dumped variables.\n", testNum);
	return 0;
}